<div class="gray_box">
    <?php //include_partial('tabs', array('selected' => $sf_request->getParameter('action'))) ?>
    <div class="registration_wrap">
        <div class="inner_blue_title"><?php echo __('My Doseyeh') ?></div>
        <br />
        <div class="inner_text"><?php echo __('Start selecting your registered courses and Preferred Doseyeh') ?></div>
        <?php include('flashes.php') ?>
        <?php if(true || !$disable_form){ ?>
        <form method="post" action="<?php echo url_for('main/LogedStd') ?>" onsubmit="return confirm('<?php echo __('Click OK to confirm your courses, you will not be able to add or delete any course during this semister.') ?>')">
        <?php } ?>
            <div id="my_doseyeh_wrap" class="registration_form_wrap my_doseyeh_wrap">
                <div id="course_instructor_holder">
                    <?php if(count($current_courses) > 0){ ?>
                        <?php foreach($current_courses as $k => $one) { ?>
                            <?php include_component('main', 'course_instructor_doseyeh', 
                                    array('delete_button'=>!$disable_form, 
                                          'index'=> $k+1, 'course_id'=> $one['course_id'], 
                                          'instructor_id'=> $one['instructor_id'],
                                          'course_instructor'=>$course_instructor)) ?>
                        <?php } ?>
                    <?php } else { ?>
                        <?php include_component('main', 'course_instructor_doseyeh', array('index'=> 1, 'delete_button'=>!$disable_form)) ?>
                    <?php } ?>
                </div>
                <br/>
                <?php if(true || !$disable_form){ ?>
                    <a href="#add_more" onclick="return add_more()" class="add_more"><?php echo __('Add More') ?></a>
                    <div class="aright"><button class=dbutton><?php echo __('Save') ?></button></div>			
                <?php } ?>
            </div>
        <?php if(true || !$disable_form){ ?>
        </form>
        <?php } ?>
    </div>
</div>
<div id="empty_row" style="display:none">
    <?php include_component('main', 'course_instructor_doseyeh', array('index'=> $k+1)) ?>
</div>
<script>
    html_before = '<div class="course_instructor_pair">';
    html_after = '</div>';
    all_html = html_before+$('#empty_row .course_instructor_pair').html()+html_after;
    
    current_index = <?php echo isset($k) ? $k : 1 ?>;
    
    function add_more(){
        current_index ++;
        all_html = all_html.replace('id="instructor_'+(current_index-1)+'"','id="instructor_'+current_index+'"');
        all_html = all_html.replace('id="course_'+(current_index-1)+'"','id="course_'+current_index+'"');
//        all_html = '<div class="new_row" style="display:none">'+all_html+'</div>';
        jQuery('#course_instructor_holder').append(all_html);
        $('select#instructor_'+current_index).selectmenu({style:'dropdown'});
        $('select#course_'+current_index).selectmenu({style:'dropdown'});
//        $('.new_row').slideDown('300');
        return false;
    }
    
    function delete_ci_row(elem){
        $(elem).parents('.course_instructor_pair:first').remove();
        return false;
    }
    
    function update_instructor(elem){
        course_id = $(elem).val();
        $.ajax({url: "<?php echo url_for('user/get_instructors_for_course') ?>?id="+course_id,context: document.body}).done(function(data) { 
            _target_select = jQuery(elem).parent().parent().parent().find('select.instructor');
            _target_select.selectmenu('destroy');
            _target_select.html(data);
            _target_select.selectmenu({style:'dropdown'});
        });
    }
    function update_doseyeh(elem){
        instructor_id = $(elem).val();
        $.ajax({url: "<?php echo url_for('user/get_doseyeh_for_instructor') ?>?id="+instructor_id,context: document.body}).done(function(data) { 
            _target_select = jQuery(elem).parent().parent().parent().find('select.doseyeh');
            _target_select.selectmenu('destroy');
            _target_select.html(data);
            _target_select.selectmenu({style:'dropdown'});
        });
    }
</script>
<?php if(false && $disable_form){ ?>
<style>
    .ui-selectmenu-menu{display:none!important}
    .ui-selectmenu{cursor:default!important}
</style>
<?php } ?>